package com.example.yiwei.crm.json;

import android.util.Log;

import com.example.yiwei.crm.entity.ManyiduEntity;
import com.example.yiwei.crm.entity.activityEntity;
import com.example.yiwei.crm.entity.dockingEntity;
import com.example.yiwei.crm.entity.jgsxEntity;
import com.example.yiwei.crm.entity.scheduleEntity;
import com.example.yiwei.crm.util.NetWorkUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/17.
 */

public class dockJson {
    public static List<dockingEntity> jsonDockingMessage(String url, String para){
        List<dockingEntity> list;
        dockingEntity docking;
        String result= NetWorkUtils.getCount(url, para);
       System.out.print("kkkkkk"+result);
        try {
            JSONObject object=new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list=new ArrayList<>();
            for (int i=0;i<array.length();i++){
                docking=new dockingEntity();
                JSONObject json=array.getJSONObject(i);
                //id
                if (json.has("KDA01")){
                    docking.setDocking_id(json.getInt("KDA01"));
                }
                //对接人姓名
                if (json.has("KDA02")){
                    docking.setDocking_name(json.getString("KDA02"));

                }
                //对接机构
                if (json.has("KDA03")){
                    docking.setDocking_mechanism(json.getString("KDA03"));
                }
                //机构属性
                if (json.has("KDA04")){
                    docking.setMechanism_attribute(json.getString("KDA04"));
                }
                //部门
                if (json.has("KDA05")){
                    docking.setDepartment(json.getString("KDA05"));
                }
                //职称
                if (json.has("KDA06")){
                    docking.setProfessional_title(json.getString("KDA06"));
                }
//                //所属地区
//                if (json.has("KDA07")){
//                    docking.setLocation(json.getInt("KDA07"));
//                }
                //联系电话
                if (json.has("KDA08")){
                    docking.setPhone_number(json.getString("KDA08"));
                }
                //拜访次数
                if (json.has("KDA09")){
                    docking.setVisit_number(json.getInt("KDA09"));
                }
                //活动次数
                if (json.has("KDA10")){
                    docking.setActivity_number(json.getInt("KDA10"));
                }
                //转诊量
                if (json.has("KDA11")){
                    docking.setReferral_amount(json.getInt("KDA11"));
                }
                //到诊量
                if (json.has("KDA12")){
                    docking.setClinical_amount(json.getInt("KDA12"));
                }
                //手术量
                if (json.has("KDA16")){
                    docking.setOperation_amount(json.getInt("KDA16"));
                }
                //送礼额
                if (json.has("KDA13")){
                    docking.setGiving_count(json.getInt("KDA13"));
                }
                //负责人
                if (json.has("KDA15")){
                    docking.setManager(json.getString("KDA15"));
                }
                //是否关注
                if (json.has("KDA17")){
                    docking.setIs_attention(json.getInt("KDA17"));
                }

                //尊称
                if (json.has("KDA20")){
                    docking.setRespectfully(json.getString("KDA20"));
                }
                //邮件
                if (json.has("KDA21")){
                    docking.setMail(json.getString("KDA21"));
                }
                //微博
                if (json.has("KDA22")){
                    docking.setWeibo(json.getString("KDA22"));
                }
                //邮编
                if (json.has("KDA23")){
                    docking.setZip_code(json.getString("KDA23"));
                }
                //地址
                if (json.has("KDA24")){
                    docking.setAddress(json.getString("KDA24"));
                }
                //备注
                if (json.has("REK01")){
                    docking.setAddtional_remark(json.getString("REK01"));
                }
                //创建时间
                if (json.has("CTS01")){
                    docking.setCreate_time(json.getString("CTS01"));
                }
                //修改时间
                if (json.has("UTS01")){
                    docking.setUpdate_time(json.getString("UTS01"));
                }
                //当前创建用户ID
                if (json.has("CID01")){
                    docking.setCurrent_create_id(json.getInt("CID01"));
                }
                //当前更新用户ID
                if (json.has("UID01")){
                    docking.setCurrent_update_id(json.getInt("UID01"));
                }
                //当前医疗机构单位ID
                if (json.has("UNT01")){
                    docking.setCurrent_medical_unit(json.getInt("UNT01"));
                }
                //当前医疗机构编码
                if (json.has("UNT02")){
                    docking.setCurrent_medical_unit_code(json.getString("UNT02"));
                }

                list.add(docking);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static dockingEntity jsonDetailedDockingMessage(String url, String para){
        String result= NetWorkUtils.getCount(url, para);
        dockingEntity docking;
        try {
            JSONObject json=new JSONObject(result);
            String boolen=json.getString("ifsuccess");
            if ("true".equals(boolen)){
                    docking=new dockingEntity();
                    //id
                    if (json.has("KDA01")){
                        docking.setDocking_id(json.getInt("KDA01"));
                    }
                    //对接人姓名
                    if (json.has("KDA02")){
                        docking.setDocking_name(json.getString("KDA02"));
                    }
                    //对接机构
                    if (json.has("KDA03")){
                        docking.setDocking_mechanism(json.getString("KDA03"));
                    }
                    //机构属性
                    if (json.has("KDA04")){
                        docking.setMechanism_attribute(json.getString("KDA04"));
                    }
                    //部门
                    if (json.has("KDA05")){
                        docking.setDepartment(json.getString("KDA05"));
                    }
                    //职称
                    if (json.has("KDA06")){
                        docking.setProfessional_title(json.getString("KDA06"));
                    }
//                    //所属地区
//                    if (json.has("KDA07")){
//                        docking.setLocation(json.getInt("KDA07"));
//                    }
                    //联系电话
                    if (json.has("KDA08")){
                        docking.setPhone_number(json.getString("KDA08"));
                    }
                    //拜访次数
                    if (json.has("KDA09")){
                        docking.setVisit_number(json.getInt("KDA09"));
                    }
                    //活动次数
                    if (json.has("KDA10")){
                        docking.setActivity_number(json.getInt("KDA10"));
                    }
                    //转诊量
                    if (json.has("KDA11")){
                        docking.setReferral_amount(json.getInt("KDA11"));
                    }
                    //到诊量
                    if (json.has("KDA12")){
                        docking.setClinical_amount(json.getInt("KDA12"));
                    }
                    //手术量
                    if (json.has("KDA16")){
                        docking.setOperation_amount(json.getInt("KDA16"));
                    }
                    //送礼额
                    if (json.has("KDA13")){
                        docking.setGiving_count(json.getInt("KDA13"));
                    }
                    //负责人
                    if (json.has("KDA15")){
                        docking.setManager(json.getString("KDA15"));
                    }
                    //负责人ID
                    if(json.has("KDA26")){
                        docking.setManager_id(json.getInt("KDA26"));
                    }
                    //是否关注
                    if (json.has("KDA17")){
                        docking.setIs_attention(json.getInt("KDA17"));
                    }
                    //尊称
                    if (json.has("KDA20")){
                        docking.setRespectfully(json.getString("KDA20"));
                    }
                    //邮件
                    if (json.has("KDA21")){
                        docking.setMail(json.getString("KDA21"));
                    }
                    //微博
                    if (json.has("KDA22")){
                        docking.setWeibo(json.getString("KDA22"));
                    }
                    //邮编
                    if (json.has("KDA23")){
                        docking.setZip_code(json.getString("KDA23"));
                    }
                    //地址
                    if (json.has("KDA24")){
                        docking.setAddress(json.getString("KDA24"));
                    }
                    //备注
                    if (json.has("REK01")){
                        docking.setAddtional_remark(json.getString("REK01"));
                    }
                    //创建时间
                    if (json.has("CTS01")){
                        docking.setCreate_time(json.getString("CTS01"));
                    }
                    //修改时间
                    if (json.has("UTS01")){
                        docking.setUpdate_time(json.getString("UTS01"));
                    }
                    //当前创建用户ID
                    if (json.has("CID01")){
                        docking.setCurrent_create_id(json.getInt("CID01"));
                    }
                    //当前更新用户ID
                    if (json.has("UID01")){
                        docking.setCurrent_update_id(json.getInt("UID01"));
                    }
                    if (json.has("UAC02")){
                        docking.setCurrent_create_name(json.getString("UAC02"));
                    }
                    //当前医疗机构单位ID
                    if (json.has("UNT01")){
                        docking.setCurrent_medical_unit(json.getInt("UNT01"));
                    }
                    //当前医疗机构编码
                    if (json.has("UNT02")){
                        docking.setCurrent_medical_unit_code(json.getString("UNT02"));
                    }
                    return docking;
                }




        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static  List<Map<String,String>> jsonDockingSpinnerMessage(String result,int l){
        List<Map<String, String>> list1;
        List<Map<String, String>> list2;
        String inforType;
        try {
            JSONObject object = new JSONObject(result);
            String boolen = object.getString("boolen");
            if (boolen.equals("success")) {
                list1 = new ArrayList<Map<String, String>>();
                list2 = new ArrayList<Map<String, String>>();
                JSONArray array = object.getJSONArray("list");
                Object aobject = new Object();
                for (int i = 0; i < array.length(); i++) {
                    Map<String, String> map = new HashMap<String, String>();
                    JSONObject json = array.getJSONObject(i);
                    inforType = json.getString("SIGNVALUE");
                    if ("YXJB".equals(inforType)) {
                        int iYXJB = json.getInt("AKJ01");
                        String sYXJB = json.getString("AKJ03");
                        map.put("YXJB01", String.valueOf(iYXJB));
                        map.put("YXJB02", sYXJB);
                        list1.add(map);
                    }
                    if ("ZT".equals(inforType)) {
                        int iZT = json.getInt("AKJ01");
                        String sZT = json.getString("AKJ03");
                        map.put("ZT01", String.valueOf(iZT));
                        map.put("ZT02", sZT);
                        list2.add(map);
                    }

                }
                if (l == 1) {
                    return list1;
                } else if (l == 2) {
                    return list2;
                }
            } else {
                Log.d("", "查询失败");
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static List<dockingEntity> jsonMangerMessage(String URL, String para){
        String result= NetWorkUtils.getCount(URL,para);
        dockingEntity docking;
        List<dockingEntity> list;
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("boolen");
            if ("success".equals(boolen)) {
                list=new ArrayList<>();
                JSONArray array = object.getJSONArray("list");
                for (int i = 0; i < array.length(); i++) {
                    JSONObject json = array.getJSONObject(i);
                    docking = new dockingEntity();
                    //负责人姓名
                    if (json.has("UAB03")) {
                        docking.setManager(json.getString("UAB03"));
                    }
                    //负责人ID
                    if (json.has("UAB01")) {
                        docking.setManager_id(json.getInt("UAB01"));
                    }
                    //所属部门
                    if (json.has("UAA03")) {
                        docking.setManager_department(json.getString("UAA03"));
                    }
                    //职位
                    if (json.has("UAB06")) {
                        docking.setManager_job(json.getInt("UAB06"));
                    }
                    list.add(docking);
                }
                return list;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static List<dockingEntity> jsonDeparmentMessage(String url, String para){
        List<dockingEntity> list;
        dockingEntity dockingEntity;
        String result= NetWorkUtils.getCount(url, para);
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("boolen");
            if ("success".equals(boolen)){
                JSONArray array=object.getJSONArray("list");
                list=new ArrayList<>();
                for (int i=0;i<array.length();i++){
                    dockingEntity=new dockingEntity();
                    JSONObject json=array.getJSONObject(i);
                    if (json.has("UAA03")){
                        dockingEntity.setManager_department(json.getString("UAA03"));
                    }
                    if (json.has("UAA01")){
                        dockingEntity.setManager_department_id(json.getString("UAA01"));
                    }
                    list.add(dockingEntity);
                }
                return list;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static List<scheduleEntity> jsonVisitMessage(String url, String para){
        String result= NetWorkUtils.getCount(url, para);
        scheduleEntity scheduleEntity;
        List<com.example.yiwei.crm.entity.scheduleEntity> list;
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("boolen");
            if ("success".equals(boolen)){
                list=new ArrayList<>();
                JSONArray array=object.getJSONArray("list");
                for (int i=0;i<array.length();i++){
                    JSONObject json=array.getJSONObject(i);
                    scheduleEntity=new scheduleEntity();
                    if (json.has("KPA01")){
                        scheduleEntity.setVisit_id(json.getInt("KPA01"));
                    }
                    if (json.has("KPA02")){
                        scheduleEntity.setSchedule_theme(json.getString("KPA02"));
                    }
                    if (json.has("KPA11")){
                        scheduleEntity.setManager_name(json.getString("KPA11"));
                    }
                    if (json.has("AKK01")){
                        scheduleEntity.setTask_state_id(json.getInt("AKK01"));
                    }
                    if (json.has("AKJ01")){
                        scheduleEntity.setPriority_id(json.getInt("AKJ01"));
                    }
                    if (json.has("AKJ03")){
                        scheduleEntity.setPriority(json.getString("AKJ03"));
                    }
                    if (json.has("AKK03")){
                        scheduleEntity.setTask_state(json.getString("AKK01"));
                    }
                    if (json.has("KPA06")){
                        scheduleEntity.setVisit_time(json.getString("KPA06"));
                    }
                    if (json.has("KPA09")){
                        scheduleEntity.setVisit_gift(json.getString("KPA09"));
                    }
                    if (json.has("KPA10")){
                        scheduleEntity.setGift_value(json.getString("KPA10"));
                    }
                    if (json.has("CID03")){
                        scheduleEntity.setCurrent_create_user_name(json.getString("CID03"));
                    }
                    if (json.has("CTS01")){
                        scheduleEntity.setCreate_time(json.getString("CTS01"));
                    }
                    if (json.has("REK01")){
                        scheduleEntity.setAdditional_remarks(json.getString("REK01"));
                    }
                    list.add(scheduleEntity);

                }
                return list;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static final List<activityEntity> jsonActivityMessage(String url, String para){
        String result= NetWorkUtils.getCount(url, para);
        List<activityEntity> list;
        activityEntity activityEntity;
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("boolen");
            if ("success".equals(boolen)) {
                list=new ArrayList<>();
                JSONArray array=object.getJSONArray("list");
                for (int i=0;i<array.length();i++){
                    activityEntity=new activityEntity();
                    JSONObject json=array.getJSONObject(i);
                    //id
                    if (json.has("KRA01")) {
                        activityEntity.setActivity_id(json.getInt("KRA01"));
                    }
                    //任务主题
                    if (json.has("KRA02")){
                        activityEntity.setActivity_theme(json.getString("KRA02"));
                    }
                    //负责人员
                    if (json.has("KRA17")){
                        activityEntity.setActivity_manager(json.getString("KRA16"));
                    }
                    //参与人员
                    if (json.has("KRA18")){
                        activityEntity.setActivity_participation(json.getString("KRA18"));
                    }
                    //优先级别
                    if (json.has("AKJ03")){
                        activityEntity.setPriority(json.getString("AKJ03"));
                    }
                    if (json.has("AKJ01")){
                        activityEntity.setPriority_id(json.getInt("AKJ01"));
                    }
                    //任务状态
                    if (json.has("AKK03")){
                        activityEntity.setTask_state(json.getString("AKK03"));
                    }
                    if (json.has("AKK01")){
                        activityEntity.setTask_state_id(json.getInt("AKK01"));
                    }
                    //任务时间
                    if (json.has("KRA07")){
                        activityEntity.setActivity_time(json.getString("KRA07"));
                    }
                    //任务描述
                    if (json.has("KRA09")){
                        activityEntity.setActivity_description(json.getString("KRA09"));
                    }
                    //发送通知
                    if (json.has("KRA10")){
                        activityEntity.setSend_notification(json.getString("KRA10"));
                    }
                    //定时提醒
                    if (json.has("AKL01")){
                        activityEntity.setRegularly_remind(json.getInt("AKL01"));
                    }
                    //对接人ID
                    if (json.has("KDA01")){
                        activityEntity.setDocking_id(json.getInt("KDA01"));
                    }
                        //活动地址
                    if (json.has("KRA11")){
                        activityEntity.setActivity_address(json.getString("KRA11"));
                    }
                        //所属部门
                    if (json.has("KRA16")){
                        activityEntity.setActivity_department(json.getString("KRA16"));
                    }
                        //备注
                    if (json.has("REK01")){
                        activityEntity.setAdditional_remarks(json.getString("REK01"));
                    }
                        //创建时间
                    if (json.has("CTS01")){
                        activityEntity.setCreate_time(json.getString("CTS01"));
                    }
                      //创建人
                    if (json.has("CID03")){
                        activityEntity.setCurrent_create_user_name(json.getString("CID03"));
                    }
                    //更新人
                    if (json.has("UID03")){
                        activityEntity.setCurrent_update_user_name(json.getString("UID03"));
                    }
                    //更新时间
                    if (json.has("UTS01")){
                        activityEntity.setUpdate_time(json.getString("UTS01"));
                    }
                    list.add(activityEntity);
                }
                return list;

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static final List<jgsxEntity> jsonJGSXMessage(String url, String para){
        String result= NetWorkUtils.getCount(url, para);
        List<jgsxEntity> list;
        jgsxEntity jgsxEntity;
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("ifsuccess");
            if ("true".equals(boolen)) {
                list=new ArrayList<>();
                JSONArray array=object.getJSONArray("list");
                for (int i=0;i<array.length();i++){
                    jgsxEntity=new jgsxEntity();
                    JSONObject json=array.getJSONObject(i);
                    //
                    if (json.has("AKN03")) {
                        jgsxEntity.setJgsx(json.getString("AKN03"));
                    }
                    if (json.has("AKN01")) {
                        jgsxEntity.setJgsx_id(json.getInt("AKN01"));
                    }
                    list.add(jgsxEntity);
                }
                return list;

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static List<ManyiduEntity>  jsonJYshMessage(String url, String para){
        String result=NetWorkUtils.getCount(url,para);
        ManyiduEntity manyiduEntity;
        List<ManyiduEntity> list;
        try {
            JSONObject object=new JSONObject(result);
            String boolen=object.getString("ifsuccess");
            if ("true".equals(boolen)) {
                list=new ArrayList<>();
                JSONArray array=object.getJSONArray("list");
                for (int i=0;i<array.length();i++){
                    manyiduEntity=new ManyiduEntity();
                    JSONObject json=array.getJSONObject(i);
                    //满意度id
                    if (json.has("KMA01")){
                        manyiduEntity.setMyd_id(json.getInt("KMA01"));
                    }
                    //负责人姓名
                    if (json.has("KMA23")){
                        manyiduEntity.setManager_name(json.getString("KMA23"));
                    }
                    //裸眼视力左眼
                    if (json.has("KMA15")){
                        manyiduEntity.setLy_left(json.getString("KMA15"));
                    }
                    //裸眼视力右眼
                    if (json.has("KMA16")){
                        manyiduEntity.setLy_right(json.getString("KMA16"));
                    }
                    //矫正视力左眼
                    if (json.has("KMA17")){
                        manyiduEntity.setJz_left(json.getString("KMA17"));
                    }
                    //矫正视力右眼
                    if (json.has("KMA18")){
                        manyiduEntity.setJz_right(json.getString("KMA18"));
                    }
                    //裸眼视力左眼
                    if (json.has("KMA02")){
                        manyiduEntity.setAly_left(json.getString("KMA02"));
                    }
                    //裸眼视力右眼
                    if (json.has("KMA03")){
                        manyiduEntity.setAly_right(json.getString("KMA03"));
                    }
                    //矫正视力左眼
                    if (json.has("KMA04")){
                        manyiduEntity.setAjz_left(json.getString("KMA04"));
                    }
                    //矫正视力右眼
                    if (json.has("KMA05")){
                        manyiduEntity.setAjz_right(json.getString("KMA05"));
                    }
                    //到院时间
                    if (json.has("KMA20L")){
                        manyiduEntity.setHospital_time(json.getString("KMA20L"));
                    }
                    //病人姓名
                    if (json.has("KAA02")){
                        manyiduEntity.setName(json.getString("KAA02"));
                    }
                    //病人ID
                    if (json.has("KAA01")){
                        manyiduEntity.setCustomer_id(json.getInt("KAA01"));
                    }
                    //性别
                    if (json.has("KAA04")){
                        manyiduEntity.setSex(json.getInt("KAA04"));
                    }
                    //年龄
                    if (json.has("KAA03")){
                        manyiduEntity.setAge(json.getInt("KAA03"));
                    }
                    //电话
                    if (json.has("KMA26")){
                        manyiduEntity.setPhone(json.getString("KMA26"));
                    }
                    //医保卡号
                    if (json.has("KMA25")){
                        manyiduEntity.setYb(json.getString("KMA25"));
                    }
                    //慢性病
                    if (json.has("KMA06")){
                        manyiduEntity.setMxb(json.getString("KMA06"));
                    }
                    //病种
                    if (json.has("AKB03")){
                        manyiduEntity.setBZ(json.getString("AKB03"));
                    }
                    if (json.has("AKB03APP")){
                        manyiduEntity.setBZ(json.getString("AKB03APP"));
                    }
                    //就诊医生
                    if (json.has("KMA21")){
                        manyiduEntity.setDoctor_name(json.getString("KMA21"));
                    }
                    //就诊情况
                    if (json.has("KMA22")){
                        manyiduEntity.setState(json.getString("KMA22"));
                    }
                    //未手术原因
                    if (json.has("KMA08")){
                        manyiduEntity.setResult(json.getString("KMA08"));
                    }
                    //就诊医院
                    if (json.has("UAA03")){
                        manyiduEntity.setHospital(json.getString("UAA03"));
                    }
                    //评价
                    if (json.has("KMA09")){
                        manyiduEntity.setManyidu(json.getInt("KMA09"));
                    }
                    //接待人
                    if (json.has("KMA12")){
                        manyiduEntity.setJdr(json.getString("KMA12"));
                    }
                    //接待人id
                    if (json.has("KMA11")){
                        manyiduEntity.setJdr_id(json.getInt("KMA11"));
                    }
                    //创建时间
                    if (json.has("CTS01L")){
                        manyiduEntity.setCreate_time(json.getString("CTS01L"));
                    }
                    if (json.has("KMA19")){
                        manyiduEntity.setSh_id(json.getInt("KMA19"));
                    }
                    //评价
                    if (json.has("KMA09")){
                        manyiduEntity.setManyidu(json.getInt("KMA09"));
                    }
                    //填写满意度时间
                    if (json.has("KMA10L")){
                        manyiduEntity.setAdd_manyidu_time(json.getString("KMA10L"));
                    }
                    list.add(manyiduEntity);
                }
                return list;

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
}
